package com.offcn.controller;

import com.offcn.entity.Book;
import com.offcn.service.OpenFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
public class OrderNacosController {
    @Resource
    private OpenFeignService openFeignService;
    @DeleteMapping(value = "/book/delete/{id}")
    public int delete(@PathVariable("id") int id){
      return openFeignService.delete(id);
    };
    @PutMapping(value = "/book/put/")
    public int update(@RequestBody Book book){
        return openFeignService.update(book);
    };

    @PostMapping(value = "/book/post/")
    public int add(@RequestBody Book book){
        return openFeignService.add(book);
    };

    @GetMapping(value = "/book/get/")
    public List<Book> select(){
        return openFeignService.select();
    };
    @GetMapping(value = "/book/get/{id}")
    public Book selectOne(@PathVariable("id") int id){
        return openFeignService.selectOne(id);
    };

    @Autowired
    private UserServiceImpl userService;
    @PostMapping("/user/post/")
    public int add(@RequestBody User user){
        userService.add(user);
        return 1;
    }

    @DeleteMapping("/user/delete/{id}")
    public int delete(@PathVariable int id){
        userService.delete(id);
        return 1;
    }

    @GetMapping("/user/get/")
    public List<User> select(){
        List<User> list = userService.select();
        return list;
    }

    @PutMapping("/user/put/")
    public int update(@RequestBody Address address){
        userService.update(address);
        return 1;
    }
}
